/*
 * Created on Jun 8, 2005
 *
 */
package com.erclab.internal.xpresso.forms;

import java.util.ArrayList;

import com.erclab.internal.xpresso.exceptions.FormException;
import com.erclab.internal.xpresso.formelements.*;

/**
 * @author Enrique Rodriguez.
 *
 */
public class FormResultSet {

	protected Form theForm;
	protected int index;
	protected int numberOfElements;
	

	public FormResultSet(Form theForm) throws FormException{
		this.theForm = theForm;
		index = -1;
		ArrayList formElements = theForm.getFormElements();
		numberOfElements = formElements.size();
		for (int i =0; i < numberOfElements; i++){
			FormElement fe = (FormElement)formElements.get(i);
			
			if (theForm.getFormParameters().getAction() != null && theForm.getFormParameters().getAction().equalsIgnoreCase("update")){
				fe.loadOriginalValue(theForm);
			}
			fe.loadLookupValues(theForm);
		}
	}

	public boolean nextFormElement(){
		index++;
		if (index < numberOfElements)
			return true;
		else
			return false;		
	}

	public String getLabel(){
		return ((FormElement)theForm.getFormElements().get(index)).getLabel();
	}
	
	public int getNumberOfElements() {
		return numberOfElements;
	}

	public String getElement(){
		return ((FormElement)theForm.getFormElements().get(index)).toHTML(theForm);
	}
	
	public String getStyle(){
		return ((FormElement)theForm.getFormElements().get(index)).getStyle();
	}

	public String getIdFormElement() {
		return "" + ((FormElement)theForm.getFormElements().get(index)).getIdFormElement();
	}
	
	public boolean isHiddenElement(){
		return ((FormElement)theForm.getFormElements().get(index)).isHidden();
	}

	public String getDescription(){
		return ((FormElement)theForm.getFormElements().get(index)).getDescription();
	}
	
	public String getErrorMessage(){
		return ((FormElement)theForm.getFormElements().get(index)).getErrorMessage();
	}
	
	public void moveFirst(){
		this.index = -1;
	}
	
}
